package com.cruise.h5.mapper;
import com.cruise.h5.pojo.entity.Post;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author cruise
 * @since 2021-03-25
 */
@Mapper
public interface PostMapper extends BaseMapper<Post> {

    /**
     * 喜欢数 + 1
     * @param postId
     */
    @Update("update b_post set like_count = like_count + 1 where id = #{postId}")
    void like(@Param("postId") String postId);

    /**
     * 喜欢数 - 1
     * @param id
     */
    @Update("update b_post set like_count = like_count - 1 where id = #{postId}")
    void cancelLike(@Param("postId") String id);

    /**
     * 评论数 +1
     * @param id
     */
    @Update("update b_post set comment_count = comment_count + 1 where id = #{postId}")
    void addCommentCount(@Param("postId") String id);

    /**
     * 评论数 -1
     * @param id
     */
    @Update("update b_post set comment_count = comment_count - 1 where id = #{postId}")
    void minusCommentCount(@Param("postId") String id);
}
